package web

import (
	"jgt-oper/src/bll"
	"jgt-oper/src/context"
	"jgt-oper/src/schema"
	"jgt-oper/src/util"
	"time"
)

// EnterHistory 门牌历史
type EnterHistory struct {
	EnterHistoryBll *bll.EnterHistory `inject:""`
}

// QueryPage 查询分页
func (a *EnterHistory) QueryPage(ctx *context.Context) error {
	ctx.WriteOperateLog("EnterHistory.QueryPage", "门牌历史管理-查询分页数据")
	params := &schema.EnterHistoryQueryParam{
		BuildingNodeID: ctx.Query("building_node_id"),
		StartTime:      util.S(ctx.Query("start_time")).Int64(),
		EndTime:        util.S(ctx.Query("end_time")).Int64(),
	}
	params.PageSize = ctx.GetPageSize()
	params.PageIndex = ctx.GetPageIndex()

	if params.EndTime == 0 {
		params.EndTime = time.Now().Unix()
	}

	total, items, err := a.EnterHistoryBll.QueryPage(params)
	if err != nil {
		return ctx.ResErrInternalServer(err)
	}
	result := map[string]interface{}{
		"list": items,
		"pagination": map[string]interface{}{
			"total":    total,
			"current":  params.PageIndex,
			"pageSize": params.PageSize,
		},
	}

	return ctx.ResSuccess(result)
}
